const app = getApp()
Page({
  data: {
    cardCur: 0,
    swiperList: [{
      id: 0,
      type: 'image',
      url: '/images/c1.jpg'
    }, {
      id: 1,
        type: 'image',
        url: '/images/c4.jpg',
    }, {
      id: 2,
      type: 'image',
      url: '/images/c6.jpg'
    }, {
      id: 3,
      type: 'image',
      url: '/images/c5.jpg'
    }],

  },
  goClass:function(res){
    let id=res.currentTarget.dataset.item._id
    wx.navigateTo({
     url:'/pages/moreClass/moreClass?id='+id,
    })
   }
   ,
   goClass1:function(res){
    let id=res.currentTarget.dataset.item._id
    wx.navigateTo({
     url:'/pages/moreClass1/moreClass?id='+id,
    })
   }
   ,
   goClass2:function(res){
    let id=res.currentTarget.dataset.item._id
    wx.navigateTo({
     url:'/pages/moreClass2/moreClass?id='+id,
    })
   }
   ,
  onShow() {
    this.tabBar();
      },
  tabBar() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1
      })
    }
},
  onLoad() {

    wx.cloud.database().collection("foods").get()
    .then(res=>{

      this.setData({
        list:res.data
      })
    })    

    
    
  },
  onReady() {
    wx.hideLoading()
  },
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      MainCur: e.currentTarget.dataset.id,

    })
  },
  VerticalMain(e) {
    let that = this;
    let list = this.data.list;
    let tabHeight = 0;
    if (this.data.load) {
      for (let i = 0; i < list.length; i++) {
        let view = wx.createSelectorQuery().select("#main-" + list[i].id);
        view.fields({
          size: true
        }, data => {
          list[i].top = tabHeight;
          tabHeight = tabHeight + data.height;
          list[i].bottom = tabHeight;     
        }).exec();
      }
      that.setData({
        load: false,
        list: list
      })
    }
    let scrollTop = e.detail.scrollTop + 20;
    for (let i = 0; i < list.length; i++) {
      if (scrollTop > list[i].top && scrollTop < list[i].bottom) {
        that.setData({
          VerticalNavTop: (list[i].id - 1) * 50,
          TabCur: list[i].id
        })
        return false
      }
    }
  }
})